package com.sfx.concurrent.demo.concurrent.AtomicTest.Atomic;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-01-18
 * Time: 17:42
 */
public class TestDemo1 {
    /**
     * AtomicInteger,AtomicLong,AtomicBoolean.....用法
     * @param args
     */
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(1);
        //前置++
        System.out.println(atomicInteger.incrementAndGet());//2
        //后置++
        System.out.println(atomicInteger.getAndIncrement());//2 3
        //前置+=val
        System.out.println(atomicInteger.addAndGet(5));//8
        //后置+=val
        System.out.println(atomicInteger.getAndAdd(5));// 8
        //得到最新值
        System.out.println(atomicInteger.get());//13


    }

}
